function[] = main(varargin)
% runs all implemented functions for the third EFME-Exercise
%
%   INPUT
%   seed....optional parameter specifying the seed for the random
%           training-/testdata separation.

    if (nargin > 0)
        rng(varargin{1});
    end

    applyPerceptronToBool();
    trainPerceptronWithFiles();
    
    %generate training and test datasets
    
    [trainingSets, testSets] = loadData(0.7,5,1);
    testSize2Class = size(testSets, 2);
        
    disp('*****************************************');
    disp('*Classification with 2 different classes*');
    disp('*****************************************');
    
    %kNN
    results = zeros(0,0,0);
    for i=1:size(trainingSets,3)
        result = kNNValidation(trainingSets(:,:,i), testSets(:,:,i), 0);
        results(:,:,i) = result;
    end
    
    average_kNN2 = averageResult(results);
    printResultkNN(average_kNN2, testSize2Class);
    %/kNN
    
    %mahalanobis
    results = zeros(0,0,0);
    for i=1:size(trainingSets,3)
        result = mahalanobisValidation(trainingSets(:,:,i), testSets(:,:,i), 0);
        results(:,:,i) = result;
    end
    average_mahal2 = averageResult(results);
    printResultMahalanobis(average_mahal2, testSize2Class);
    %/mahalanobis
    
    %perceptron
    results = zeros(0,0,0);
    for i=1:size(trainingSets,3)
        result = perceptronValidation(trainingSets(:,:,i), testSets(:,:,i), 0,1);
        results(:,:,i) = result;
    end
    average_percep2 = averageResult(results);
    printResultPerceptron(average_percep2, testSize2Class);
    %/perceptron
    
    disp('*****************************************');
    disp('*Classification with 6 different classes*');
    disp('*****************************************');
    
    [trainingSets, testSets] = loadData(0.7,5,2);
    testSize6Class = size(testSets, 2);
    
    %kNN
    results = zeros(0,0,0);
    for i=1:size(trainingSets,3)
        result = kNNValidation(trainingSets(:,:,i), testSets(:,:,i),0);
        results(:,:,i) = result;
    end
    
    average_kNN6 = averageResult(results);
    printResultkNN(average_kNN6, testSize6Class);
    %/kNN
    
    %mahalanobis
    results = zeros(0,0,0);
    for i=1:size(trainingSets,3)
        result = mahalanobisValidation(trainingSets(:,:,i), testSets(:,:,i), 0);
        results(:,:,i) = result;
    end
    average_mahal6 = averageResult(results);
    printResultMahalanobis(average_mahal6, testSize6Class);
    %/mahalanobis
    
    %perceptron
    results = zeros(0,0,0);
    for i=1:size(trainingSets,3)
        result = perceptronValidation(trainingSets(:,:,i), testSets(:,:,i), 0,2);
        results(:,:,i) = result;
    end
    average_percep6 = averageResult(results);
    printResultPerceptron(average_percep6, testSize6Class);
    %/perceptron
    
    %*********************************
    %*************CHARTS**************
    %*********************************
    
    factor2 = 100 / testSize2Class;
    factor6 = 100 / testSize6Class;
    average_kNN2 = average_kNN2 * factor2;
    average_kNN6 = average_kNN6 * factor6;
    average_mahal2 = average_mahal2(2:end,:) * factor2;
    average_mahal6 = average_mahal6(2:end,:) * factor6;
    average_percep2 = average_percep2 * factor2;
    average_percep6 = average_percep6 * factor6;
    
    plotDetails(average_kNN2, average_kNN6, average_mahal2, average_mahal6);
    plotAlgorithmComparison(average_kNN2, average_kNN6, average_mahal2, average_mahal6, average_percep2, average_percep6);
   
    names = getSelectionNames();
    %disp(names);
    plotKNNresults(average_kNN2,names,'k-NN results for 2 class problem');
    plotKNNresults(average_kNN6,names,'k-NN results for 6 class problem');
    
    totalResults2 = cat(1, average_kNN2, average_mahal2, average_percep2);
    plottotalResults(totalResults2,names,'All results for 2 class problem',40,100);
    
    totalResults6 = cat(1, average_kNN6, average_mahal6, average_percep6);
    plottotalResults(totalResults6,names,'All results for 6 class problem',30,80);
%     averaged_k_kNN2 = averageRow(average_kNN2);
%     disp(averaged_k_kNN2);
%     
%     averaged_mahal2 = averageRow(average_mahal2(2:end,:));
%     disp(averaged_mahal2);
%     
%     disp(average_percep2);
%     
%     averaged_k_kNN6 = averageRow(average_kNN6);
%     disp(averaged_k_kNN6);
%     
%     averaged_mahal6 = averageRow(average_mahal6(2:end,:));
%     disp(averaged_mahal6);
%     
%     disp(average_percep6);
end
